<!doctype html>
<html>

<head>
  <meta charset="utf-8" />
  {load_css file="weiboface.css" module="emotion"}
  {load_js file="weiboface.js" module="emotion"}
  <script>
    weiboFaceInit({
      emotionUrl: "{AnUrl('emotion/get')}"
    });
  </script>
</head>

<body>

<textarea id="faceTextarea" style="margin: 2px; width: 738px; height: 30px;"></textarea>
<button id="face">表情</button><button id="parse">解析</button>
<hr />
<div id="parsedHtml"></div>

<hr />

<textarea id="faceTextarea1" style="margin: 2px; width: 650px; height: 57px;"></textarea>
<button id="face1">表情</button>

<hr />

<textarea id="faceTextarea2" style="margin: 2px; width: 666px; height: 660px;"></textarea>
<button id="face2">表情</button>

<script>
weiboFace( document.getElementById( 'face' ), document.getElementById( 'faceTextarea' ) );
weiboFace( document.getElementById( 'face1' ), document.getElementById( 'faceTextarea1' ) );
weiboFace( 'face2', 'faceTextarea2' );
</script>

<script type="text/javascript">
var parseObj = document.getElementById( 'parse' );
var parseTextObj = document.getElementById( 'faceTextarea' );
addEvent( parseObj, 'click', function(){
  var text = parseTextObj.value;
  var html = weiboFace.parse( text );
  var htmlDiv = document.getElementById( 'parsedHtml' );
  htmlDiv.innerHTML = html;
});

function addEvent(element, types, callback) {
  if ( !element ) {
    error( 'addEvent element is null.' );
  }
  types = types.split(" ");
  for(var t= 0, len=types.length; t<len; t++) {
    if(element.addEventListener){
      element.addEventListener(types[t], callback, false);
    }
    else if(document.attachEvent){
      element.attachEvent("on"+ types[t], callback);
    }
  }
}
</script>
</body>

</html>